﻿namespace EasyCMS.Common.Querys
{
    using System;
    using Pismire;



    [System.Runtime.Serialization.DataContractAttribute(Name = "Comment", Namespace = "http://schemas.datacontract.org/2004/07/EasyCMS.Common.Querys")]
    public class Comment : Pismire.Querys.QueryBase
    {
        #region key
        /// <summary>
        /// 缓存键
        /// </summary>
        public override string Key
        {
            get { return string.Format(KeyFormat, CategoryID, SubjectID, MemberID, Status); }
        }
        private const string KeyFormat = "Comment_CategoryID{0}SubjectID{1}MemberID{2}Status{3}";
        #endregion

        #region CategoryID
        /// <summary>
        /// CategoryID
        /// </summary>
        public int CategoryID
        {
            get { return m_CategoryID; }
            set
            {
                m_CategoryID = value;
                this.HasCategoryID = (value > -1) ? true : false;
            }
        }
        private int m_CategoryID;
        public bool HasCategoryID { get; private set; }
        public static ExcuteState CategoryID_Validate(ref int categoryID)
        {
            return categoryID.Validation("CategoryID").MoreThan(-1).State;
        }
        #endregion

        #region SubjectID
        /// <summary>
        /// SubjectID
        /// </summary>
        public int SubjectID
        {
            get { return m_SubjectID; }
            set
            {
                m_SubjectID = value;
                this.HasSubjectID = (value > -1) ? true : false;
            }
        }
        private int m_SubjectID;
        public bool HasSubjectID { get; private set; }
        public static ExcuteState SubjectID_Validate(ref int subjectID)
        {
            return subjectID.Validation("SubjectID").MoreThan(-1).State;
        }
        #endregion

        #region MemberID
        /// <summary>
        /// MemberID
        /// </summary>
        public int MemberID
        {
            get { return m_MemberID; }
            set
            {
                m_MemberID = value;
                this.HasMemberID = (value > -1) ? true : false;
            }
        }
        private int m_MemberID;
        public bool HasMemberID { get; private set; }
        public static ExcuteState MemberID_Validate(ref int memberID)
        {
            return memberID.Validation("MemberID").MoreThan(-1).State;
        }
        #endregion

        #region Status
        /// <summary>
        /// Status
        /// </summary>
        public Enums.CommentStatus Status
        {
            get { return m_Status; }
            set
            {
                m_Status = value;
                if (value.Validation("CommentStatus").NotDefault().State.Succeed)
                {
                    HasType = true;
                }
            }
        }
        private Enums.CommentStatus m_Status;
        public bool HasType { get; private set; }
        #endregion

        #region checkMe
        /// <summary>
        /// 检查合法性
        /// </summary>
        /// <returns></returns>
        public override ExcuteState CheckMe()
        {
            //初始化
            ExcuteState state = null;

            state = CategoryID_Validate(ref this.m_CategoryID);
            if (!state.Succeed) return state;

            state = SubjectID_Validate(ref this.m_SubjectID);
            if (!state.Succeed) return state;

            state = MemberID_Validate(ref this.m_MemberID);
            if (!state.Succeed) return state;

            //返回
            return state;
        }
        #endregion
    }
}
